import { Toast } from 'vant'

export const Toast1s = (str) => {
    Toast({message: str, duration: 1000})
}

export const wid = (imgSize) => {
    return window.document.documentElement.clientWidth / 375  * imgSize
}

export const isInViewPort = (element, num) => {
    const viewWidth = window.innerWidth || document.documentElement.clientWidth;
    const viewHeight =
          window.innerHeight || document.documentElement.clientHeight;
    const { top, right, bottom, left, y } = element.getBoundingClientRect();
    
    return y < num;
}

export const fixPos = (el) => {
    el.style.position = "fixed";
    el.style.zIndex = "10000" 
    el.style.top = "0";
    el.style.left = "0";
    el.style.right = "0"
}

export const unfixPos = (el) => {
  el.style.position = "";
  el.style.zIndex = "" 
  el.style.top = "";
  el.style.left = "";
  el.style.right = ""
}

// BUG
export function debounce(func,delay){
    let timer = null
    return function(...args){
      if(timer) clearTimeout(timer)
      timer = setTimeout(() =>{
         func.apply(this,args)
      },delay)
    }
  }